package com.gpframework.module.controller.order;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;
import java.util.Arrays;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gpframework.common.annotation.Log;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.enums.BusinessType;
import com.gpframework.module.order.domain.GpDestinationNoLog;
import com.gpframework.module.order.domain.vo.GpDestinationNoLogVo;
import com.gpframework.module.order.domain.req.GpDestinationNoLogReq;
import com.gpframework.module.order.domain.req.GpDestinationNoLogAdd;
import com.gpframework.module.order.domain.req.GpDestinationNoLogUpdate;
import com.gpframework.module.order.service.IGpDestinationNoLogService;
import com.gpframework.common.utils.poi.ExcelUtil;
import javax.validation.Valid;
import io.swagger.annotations.*;
import com.gpframework.common.core.page.TableDataInfo;
/**
 * @ClassName GpDestinationNoLogController
 * @Author gpframework
 * @Date 2023-08-28
 * @Version 1.0.0
 * @Description 车次发车记录Controller
 */
@Validated
@Api(tags = "车次发车记录")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@SuppressWarnings({"rawtypes","unchecked"})
@RequestMapping("/order/destinationNoLog" )
public class GpDestinationNoLogController extends BaseController {

    private final IGpDestinationNoLogService iGpDestinationNoLogService;

 /**
  * @Description 分页
  * @Author gpframework
  * @Date 2023-08-28
  * @Param gpDestinationNoLog
  * @Return TableDataInfo
 */
    @ApiOperation("列表")
    @PreAuthorize("@ss.hasPermi('order:destinationNoLog:list')")
    @GetMapping("/list")
    public TableDataInfo<GpDestinationNoLogVo> list(GpDestinationNoLogReq gpDestinationNoLogReq)
    {
        startPage();
        QueryWrapper<GpDestinationNoLog> lqw = new QueryWrapper<GpDestinationNoLog>();
        gpDestinationNoLogReq.generatorQuery(lqw,true);
        List<GpDestinationNoLogVo> list = iGpDestinationNoLogService.listVo(lqw);
        return getDataTable(list);
    }

    /**
     * @Description 新增
     * @Author gpframework
     * @Date 2023-08-28
     * @Param gpDestinationNoLog
     * @Return TableDataInfo
     */
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('order:destinationNoLog:add')" )
    @Log(title = "添加车次发车记录" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GpDestinationNoLogAdd gpDestinationNoLogAdd) {
        GpDestinationNoLog gpDestinationNoLog = Convert.convert(new TypeReference<GpDestinationNoLog>() {}, gpDestinationNoLogAdd);
        return toAjax(iGpDestinationNoLogService.save(gpDestinationNoLog) ? 1 : 0);
    }

    /**
     * @Description 修改
     * @Author gpframework
     * @Date 2023-08-28
     * @Param gpDestinationNoLog
     * @Return TableDataInfo
     */
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('order:destinationNoLog:edit')" )
    @Log(title = "修改车次发车记录" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody GpDestinationNoLogUpdate gpDestinationNoLogUpdate) {
        GpDestinationNoLog gpDestinationNoLog = Convert.convert(new TypeReference<GpDestinationNoLog>() {}, gpDestinationNoLogUpdate);
        return toAjax(iGpDestinationNoLogService.updateById(gpDestinationNoLog) ? 1 : 0);
    }


    /**
     * @Description 导出
     * @Author gpframework
     * @Date 2023-08-28
     * @Param gpDestinationNoLog
     * @Return TableDataInfo
     */

    @PreAuthorize("@ss.hasPermi('order:destinationNoLog:export')" )
    @Log(title = "导出车次发车记录" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(GpDestinationNoLogReq gpDestinationNoLogReq) {
        QueryWrapper<GpDestinationNoLog> lqw = new QueryWrapper<GpDestinationNoLog>();
        gpDestinationNoLogReq.generatorQuery(lqw,true);
        List<GpDestinationNoLogVo> list = iGpDestinationNoLogService.listVo(lqw);
        ExcelUtil<GpDestinationNoLogVo> util = new ExcelUtil<GpDestinationNoLogVo>(GpDestinationNoLogVo. class);
        return util.exportExcel(list, "destinationNoLog" );
    }

    /**
     * @Description 详情
     * @Author gpframework
     * @Date 2023-08-28
     * @Param gpDestinationNoLog
     * @Return TableDataInfo
     */
    @ApiOperation("详情")
    @PreAuthorize("@ss.hasPermi('order:destinationNoLog:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult<GpDestinationNoLogVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iGpDestinationNoLogService.getVoById(id));
    }



    /**
     * @Description 删除
     * @Author gpframework
     * @Date 2023-08-28
     * @Param gpDestinationNoLog
     * @Return TableDataInfo
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('order:destinationNoLog:remove')" )
    @Log(title = "删除车次发车记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iGpDestinationNoLogService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
